package com.supeng.PMdepot.net;

import android.app.Activity;

import com.google.gson.Gson;
import com.supeng.PMdepot.common.Constant;
import com.supeng.PMdepot.entity.PanDianReq;
import com.supeng.PMdepot.entity.ServiceResult;
import com.supeng.PMdepot.entity.WfChaiXiangReq;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

/**
 * 接口类
 * 苏鹏
 * 2016/07/04
 */
public class Api {
   //status??
    /**
     * 登录接口
     */
    public static void login(Activity context, String username, String psd,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("username", username);
        map.put("psd",psd);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/User/Login", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 入库
     * @param context
     * @param barcode 条码
     * @param position  仓位条码
     * @param netCallBack
     * @param rspCls
     */
    public static void storageIn(Activity context, String barcode, String position,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("barcode", barcode);
        map.put("position",position);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/In", new JSONObject(map), null, netCallBack, rspCls);

    }



    /**
     * 查询派工单信息
     * @param context
     * @param paigongdan 派工单条码
     * @param netCallBack
     * @param rspCls
     */
    public static void searchPaigong(Activity context, String paigongdan,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("paigongdan", paigongdan);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/PaiGong", new JSONObject(map), null, netCallBack, rspCls);

    }
    /**
     * 查询拆箱信息
     * @param context
     * @param barcode 拆箱条码
     * @param netCallBack
     * @param rspCls
     */
    public static void searchChaixiang(Activity context, String barcode,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("barcode", barcode);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/searchChaixiang", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 移库信息查询
     * @param context
     * @param barcode
     * @param netCallBack
     * @param rspCls
     */
    public static void yksearch(Activity context, String barcode,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("barcode", barcode);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/yksearch", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 移库
     * @param context
     * @param barcode 条码
     * @param dycangku 待移库信息
     * @param dycangwei 待移库仓位
     * @param ykcangwei  移库仓位
     * @param netCallBack
     * @param rspCls
     */
    public static void yiku(Activity context, String barcode,String dycangku,String dycangwei,String ykcangwei,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("barcode", barcode);
        map.put("dycangku", dycangku);
        map.put("dycangwei", dycangwei);
        map.put("ykcangwei", ykcangwei);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/yiku", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 查询产品
     * @param context
     * @param barcode
     * @param netCallBack
     * @param rspCls
     */
    public static void searhchanpin(Activity context, String barcode,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("barcode", barcode);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/searhchanpin", new JSONObject(map), null, netCallBack, rspCls);

    }
    /**
     * 锁库
     * @param context
     * @param quyu
     * @param netCallBack
     * @param rspCls
     */
    public static void suoku(Activity context, String quyu, boolean isSuoku,String pandianbianhao,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("quyu", quyu);
        map.put("isSuoku", isSuoku);
        map.put("pandianbianhao", pandianbianhao);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/suoku", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 盘点
     * @param context
     * @param panDianReq
     * @param netCallBack
     * @param rspCls
     */
    public static void pandian(Activity context, PanDianReq panDianReq, NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {

        try {
            NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/pandian", new JSONObject(new Gson().toJson(panDianReq)), "盘点处理中...", netCallBack, rspCls);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    /**
     * 拆箱
     * @param context
     * @param tiaoma 拆箱条码
     * @param netCallBack
     * @param rspCls
     */
    public static void chaixiang(Activity context, String tiaoma,String weight1,String shuliang1,String weight2,String shuliang2,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("tiaoma", tiaoma);
        map.put("weight1", weight1);
        map.put("shuliang1", shuliang1);
        map.put("weight2", weight2);
        map.put("shuliang2", shuliang2);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/chaixiang", new JSONObject(map), "拆箱中...", netCallBack, rspCls);

    }
    /**
     * 出库
     * @param context
     * @param barcode 条码
     * @param paigonganId  派工单条码 其他出库就写""
     * @param netCallBack
     * @param rspCls
     */
    public static void storageOut(Activity context, String barcode, String paigonganId,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("barcode", barcode);
        map.put("paigonganId",paigonganId);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/Out", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 查询在制产品根据派工单查询
     * @param context
     * @param barcode
     * @param netCallBack
     * @param rspCls
     */
    public static void zaizhisearhchanpin(Activity context, String barcode,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("barcode", barcode);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/zaizhisearhchanpin", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 在制品入库
     * @param context
     * @param barcode 条码
     * @param position  仓位条码
     * @param netCallBack
     * @param rspCls
     */
    public static void ZaiZhiIn(Activity context, String barcode, String position,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("barcode", barcode);
        map.put("position",position);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/ZaiZhiIn", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 查询外发拆箱
     * @param context
     * @param barcode 拆箱条码
     * @param netCallBack
     * @param rspCls
     */
    public static void xcsearchChaixiang(Activity context, String barcode,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("barcode", barcode);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/xcsearchChaixiang", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 外发拆箱
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void wfchaixiang(Activity context, WfChaiXiangReq wfChaiXiangReq, NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {

        try {
            NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/wfchaixiang", new JSONObject(new Gson().toJson(wfChaiXiangReq)), null, netCallBack, rspCls);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    /**
     * 查询报修
     */
    public static void baoXiuSearch(Activity context, String status,boolean aboutMe, int pageIndex,int pageSize,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("status", status);//状态（10.未受理，20.已受理，30.已完成，40.撤销）
        map.put("pageIndex",pageIndex);
        map.put("pageSize",pageSize);
        map.put("aboutMe",aboutMe);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/getList", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 查询删除列表
     * @param context
     * @param pageIndex
     * @param pageSize
     * @param netCallBack
     * @param rspCls
     */
    public static void getdelDetail(Activity context, int pageIndex,int pageSize,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("pageIndex",pageIndex);
        map.put("pageSize",pageSize);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/getDelList", new JSONObject(map), null, netCallBack, rspCls);

    }
    /**
     * 获取设备列表
     */
    public static void machine(Activity context,String key,int pageIndex, int pageSize,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("key",key);
        map.put("pageIndex", pageIndex);
        map.put("pageSize",pageSize);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Machine/machine", new JSONObject(map), null, netCallBack, rspCls);

    }
    /**
     * 根据设备编号查询
     */
    public static void machineGetInfo(Activity context,String macid,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("macid",macid);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Machine/getInfo", new JSONObject(map), "查询设备中..", netCallBack, rspCls);

    }

    /**
     * 添加报修
     */
    public static void baoxiuAdd(Activity context,String macid,String mtncContent,String img,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("macid",macid);
        map.put("mtncContent",mtncContent);
        map.put("img",img);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/Add", new JSONObject(map), null, netCallBack, rspCls);

    }


    /**
     * 查询报修详细
     * wxid 报修ID
     */
    public static void baoXiuDetail(Activity context, String wxid,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("wxid", wxid);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/getInfo", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 更新维修单状态
     * wxid 报修ID
     * context 更新描述
     * 状态（cx.撤销，sl.受理，th.退回，sc.删除，hf.恢复，jh.激活）
     */
    public static void updateStatus(Activity context, String wxid,String status,String contextt,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("wxid", wxid);
        map.put("status",status);
        map.put("context",contextt);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/updateStatus", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 新增维修明细
     * wxid 报修ID
     * kind 类型（10.报修补充,20.维修说明,70.结案）
     */
    public static void addWXMingXi(Activity context, String wxid,String kind,String wxContent,String img,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("wxid", wxid);
        map.put("kind",kind);
        map.put("wxContent",wxContent);
        map.put("img",img);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWXDetail/Add", new JSONObject(map), null, netCallBack, rspCls);

    }
    /**
     * 查询维修记录
     * wxid 报修ID
     */
    public static void wXMingXiList(Activity context, String wxid,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("wxid", wxid);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWXDetail/getList", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 根据关键词查询列表
     * key 关键词
     */
    public static void getListByKey(Activity context, boolean aboutMe,String key,int pageIndex,int pageSize,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("aboutMe",aboutMe);
        map.put("key", key);
        map.put("pageIndex",pageIndex);
        map.put("pageSize",pageSize);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/getListByKey", new JSONObject(map), null, netCallBack, rspCls);

    }


//    /**
//     * 维修人员查询
//     * status 未处理 处理中 已处理
//     */
//    public static void weixiuSearch(Activity context, String status,int pageIndex,int pageSize,boolean aboutMe,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
//        Map map = new HashMap();
//        map.put("status", status);
//        map.put("pageIndex", pageIndex);
//        map.put("pageSize", pageSize);
//        map.put("aboutMe", aboutMe);
//        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/getListByModify", new JSONObject(map), null, netCallBack, rspCls);
//
//    }



    /**
     * 更新
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void checkUpdate(Activity context, final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        NetUtils.post(context, Constant.getBaseUrl() + "/api/System/CheckUpdate",  new JSONObject(map), null, netCallBack, rspCls);
    }
}
